package cn.itsource.controller;

import cn.itsource.domain.Emp;
import cn.itsource.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//创建本类的对象并交给spring管理（放到spring容器中）
@Controller
//@RestController //复合注解， 包含了@Controller和@ResponseBody的作用
public class HelloController {
    @Autowired //自动注入对象， 从容器中拿取
    private HelloService helloService;

    @RequestMapping("/hello") //映射url访问路径, 可以写在类上面，也可以写在方法上
    public String hello(Model model){
        List<Emp> empList = helloService.hello();
        model.addAttribute("emps",empList);

        model.addAttribute("test","<h1>你好</h1>");
        return "abc";
    }

    @RequestMapping("/login")
    public String login(){
        return "login";
    }

}
